package com.fcat.common.monitor;

import com.fcat.springboot.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;


/*import org.springframework.session.data.redis.RedisFlushMode;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;*/

/**
 * ${DESCRIPTION}
 *
 * @author xiangfei
 * @create 2017-05-25 12:44
 */
@SpringBootApplication(scanBasePackages = {"com.fcat"})
@ServletComponentScan("com.fcat")
//@ComponentScan("com.fcat")
@EnableEurekaClient
@EnableFeignClients
@EnableDiscoveryClient  //激活eureka中的DiscoveryClient实现
@EnableAsync
@EnableCaching
@EnableScheduling
public class MonitorBootstrap implements CommandLineRunner {

    @Value("${server.port}")
    private String serverPort;
    @Autowired
    private RedisService redisService;

    public static void main(String[] args) {
        SpringApplication.run(MonitorBootstrap.class, args);
    }

    @Bean
    RestTemplate restTemplate(ClientHttpRequestFactory simpleClientHttpRequestFactory){
        return new RestTemplate(simpleClientHttpRequestFactory);
    }

    @Bean
    public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setReadTimeout(5000);//ms
        factory.setConnectTimeout(15000);//ms
        return factory;
    }

    @Override
    public void run(String... strings) throws Exception {
        System.err.println("------------------------------------------------------- http://localhost:"+serverPort+"/swagger-ui.html");
    }

}
 